#include <iostream>
#include <string>
using namespace std;

class President
{
private:
    //构造函数私有, 构造函数必须有方法体, 天坑 禁止直接实例化一个对象
    President(){};
    //复制构造函数私有, 禁止复制
    President(const President&);
    //类复制运算符= 私有
    const President& operator = (const President&);
    string name;
public:
    void setName(string temp_name)
    {
        name = temp_name;
    }

    string getName(void)
    {
        return name;
    }

    static President& getInstance()
    {
        //static 属性在所有对象之间共用 static 方法中的局部变量 只会被初始化一次
        static President onlyInstance;
        cout << "Address of single only instance:" << &onlyInstance << endl;
        return onlyInstance; //如果不使用引用 在此会尝试复制一个新对象返回,同时销毁原有对象
    }

};

int main(int argc, char const *argv[])
{
    President& myPresident = President::getInstance();
    cout << "Address of single instance during main function:" << &myPresident << endl;
    myPresident.setName("Bush");
    cout << myPresident.getName() << endl;
    /* code */
    return 0;
}
